clear all;close all;clc

for Hard0_Soft1 = 0:1
Hard0_Soft1
    R_control_noise_Cond1 = [38/100 29/100 29/100 26/100 36/100 21/100 31/100 40/100]; % left -60, right +60

    R_Processed_noise_Cond1 = [99/100 98/100 97/100 97/100 97/100 95/100 98/100 97/100]; % % left -60, right +60

    R_Processed_noise_Cond2 = [95/100 97/100 96/100 98/100 96/100 96/100 99/100 98/100]; % % left -15, right +15

    R_Processed_noise_Cond3 = [89/100 89/100 86/100 89/100 93/100 89/100 91/100 90/100]; % % 0, right +5

    R_Processed_noise_Cond4 = [0/100 0/100 0/100 0/100 0/100 0/100 0/100 0/100]; % % Right +85, right +90

    R_Processed_noise_Cond5 = [0/100 2/100 0/100 0/100 3/100 3/100 0/100 4/100]; % % Right +75, right +105

    R_Processed_noise_Cond6 = [4/100 4/100 7/100 6/100 9/100 4/100 5/100 3/100]; % % Back 180, 175


    % ===
    R_Soft_control_noise_Cond1 = [38/100 29/100 29/100 26/100 36/100 21/100 31/100 40/100]; % left -60, right +60

    R_Soft_noise_Cond1 = [93/100 79/100 74/100 71/100 83/100 77/100 73/100 73/100]; % % left -60, right +60

    R_Soft_noise_Cond2 = [97/100 83/100 65/100 66/100 70/100 78/100 79/100 79/100]; % % left -15, right +15

    R_Soft_noise_Cond3 = [64/100 82/100 71/100 71/100 76/100 68/100 66/100 71/100]; % % 0, right +5

    R_Soft_noise_Cond4 = [36/100 14/100 5/100 1/100 5/100 4/100 5/100 3/100]; % % Right +85, right +90

    R_Soft_noise_Cond5 = [7/100 24/100 8/100 27/100 19/100 21/100 28/100 16/100]; % % Right +75, right +105

    R_Soft_noise_Cond6 = [11/100 53/100 42/100 53/100 54/100 61/100 54/100 53/100]; % % Back 180, 175

    titles={'A. Front, −60^{o}&+60^{o}','B. Front, −15^{o}&+15^{o}','C. Front, 0^{o}&+5^{o}','D. Side, +85^{o}&+90^{o}','E. Side, +65^{o}&+90^{o}','F. Back, +180^{o}&+175^{o}'};

    figure('position',[100 100 800 450]);
    n=100;
    alpha=0.05;
    outP=f_out_plot;
    mean(R_control_noise_Cond1)
    for i=1:6
        subplot('position',outP(i,:))
        if Hard0_Soft1==0
            eval(['tem = R_Processed_noise_Cond' num2str(i) ';'])
        elseif Hard0_Soft1==1
            eval(['tem = R_Soft_noise_Cond' num2str(i) ';'])
        end
        pbar = [R_control_noise_Cond1' tem' ].*100;
        mean(tem)
        bar(pbar)
%         pause7

        for icond = 1:2
            for ib = 1:length(pbar)
                CI(icond,ib) = f_confid_I(n,pbar(ib,icond)./100,alpha).*100;
            end
            hold on;
            errorbar((1:8)+0.3.*(icond-1.5),pbar(:,icond),CI(icond,:),'k.');
        end
        xlabel('Sentence Group #');
        ylabel('Percent Correct (%)')
        box off;
        ylim([0 115])
        title(titles{i})
        if i==2
            if Hard0_Soft1==0
                t=text(5,145,['HRTF-1, Hard Mask, SNR = 0 dB'],'horizontalalignment','center');set(t,'fontsize',12)
            else
                t=text(5,145,['HRTF-1, Soft Mask, SNR = 0 dB'],'horizontalalignment','center');set(t,'fontsize',12)
            end
        end
        for igroup = 1:8
            p1=pbar(igroup,1)./100;
            p2=pbar(igroup,2)./100;
            out = f_ztest(p1,p2,100,100);
            if out.p < 0.05/6 & p1<p2
                plot(igroup-0.1,max(pbar(igroup,:))+CI(1,igroup)+4,'k*');
            end            
        end
        if i==4
            legend('Control','Processed')
            legend boxoff
        end

    end

    if Hard0_Soft1==0
        exportgraphics(gcf, 'BB_S1_Figure6_HardResults.png', 'Resolution', 600,'ContentType', 'vector')
    elseif Hard0_Soft1==1
        exportgraphics(gcf, 'BB_S1_Figure8_SoftResults.png', 'Resolution', 600,'ContentType', 'vector')
    end

end